import time

from selenium import webdriver  # 包含了平时点击，输入等普通事件都在这里

'''
    8大定位方式：
        XPATH: 1个顶7个  通用型定位方式
        
        id:
        name:
        class:
        css_selector:
        tag: 标签定位
        link_text:超链接定位
        partial_link_text:局部文本
    
'''




# 打开浏览器
from selenium.webdriver.common.by import By

driver = webdriver.Chrome()


# 最大化
driver.maximize_window()

# 访问一个网址
driver.get("http://www.baidu.com")

# 定位输入框
# ele = driver.find_element(By.ID,"kw")
ele = driver.find_element(By.XPATH,"//input[@id='kw' and  @name='wd']")
ele.send_keys("jason")

# 点击百度一下
# ele2 = driver.find_element(By.ID,"su")
ele2 = driver.find_element(By.XPATH,"//input[@id='su' and  @value='百度一下']")
ele2.click()

time.sleep(3)

# 自动截图
driver.save_screenshot("a.jpg")

#  浏览器自动关闭
driver.close()






















